<?php
namespace app\index\controller;

class Wx{

    public $appId = "wxde6841d6252441f9";
    public $appSecret = "01e68a1b08e5746b65106ac4979dd456";
    public $access_token;
    public $jsapi_ticket;

    /**
     * get请求获取
     * @param $url
     * @return mixed
     */
    public function actionGet ($url)
    {
        $get = file_get_contents($url);

        $json = json_decode($get, true);

        return $json;
    }

    /**
     * 获取access_token
     * @return $this
     */
    public function getAccessToken ()
    {
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}";

        $json=$this->actionGet($url);

        $this->access_token = $json['access_token'];

        return $this;
    }

    /**
     * 利用access_token换取jsapi_ticket
     * @return $this
     */
    public function getJsapiTicket ()
    {
        $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$this->access_token}&type=jsapi";


        $json=$this->actionGet($url);

        $this->jsapi_ticket =$json['ticket'];

        return $this;
    }

}
